package com.kly.user.enums;

import com.fqgj.common.utils.CollectionUtils;
import com.fqgj.common.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * appsflyer 推送类型
 */
public enum AppsFlyerEventDefType {

    Registration("Registration", "fb_mobile_complete_registration", "注册用户信息", EventPushType.PushData),
    Connect("Connect", "Contact", "建联用户信息", EventPushType.PushData),
    Active_Chat("Active_Chat", "fb_mobile_tutorial_completion", "有效会话用户信息", EventPushType.PushData),
    Deep_Chat("Deep_Chat", "fb_mobile_level_achieved", "深度会话用户信息", EventPushType.PushData),
    D0_Purchase("D0_Purchase", "Subscribe", "新用户充值信息及收入", EventPushType.PushDataAndIncome),
    Purchase("Purchase", "fb_mobile_purchase", "用户充值信息及收入", EventPushType.PushDataAndIncome),

    ;

    private final String eventCode;

    private final String value;

    private final String description;
    /**
     * 1-只推送事件 2-只推送值 3-推送值和收入
     */
    private final EventPushType type;

    public EventPushType getType() {
        return type;
    }

    AppsFlyerEventDefType(String eventCode, String value, String description, EventPushType type) {
        this.eventCode = eventCode;
        this.value = value;
        this.description = description;
        this.type = type;
    }

    public String getEventCode() {
        return eventCode;
    }

    public String getValue() {
        return value;
    }

    public String getDescription() {
        return description;
    }


    public static AppsFlyerEventDefType fromCode(String type) {
        if (Objects.isNull(type)) {
            return null;
        }
        for (AppsFlyerEventDefType userStatus : values()) {
            if (userStatus.getEventCode().equalsIgnoreCase(type)) {
                return userStatus;
            }
        }
        return null;
    }

    public static boolean enablePushDataSwitch(List<String> eventTypes, AppsFlyerEventDefType pushType) {
        if (CollectionUtils.isEmpty(eventTypes) || pushType == null) {
            return false;
        }
        return eventTypes.parallelStream().anyMatch(o -> o.equals(pushType.getEventCode()));
    }

}
